#ifndef CONFIG_H
#define CONFIG_H

// 系统配置
#define SYSTEM_VERSION "1.0.0"
#define DEVICE_NAME "智能学习桌助手"

// 硬件引脚配置
#define WIFI_TX_PIN 2
#define WIFI_RX_PIN 3
#define MIC_PIN 0       // ADC0
#define AUDIO_OUT_PIN 4 // PWM输出
#define BUTTON_PIN 5
#define LED_PIN 6

// 音频配置
#define SAMPLE_RATE 16000
#define AUDIO_BUFFER_SIZE 1024
#define MIC_THRESHOLD 500 // 语音检测阈值
#define AUDIO_GAIN 128    // 音频增益

// 语音识别配置
#define WAKE_WORD "小助手"
#define WAKE_WORD_TIMEOUT 5000 // 5秒超时
#define VOICE_TIMEOUT 10000    // 10秒语音超时
#define SILENCE_THRESHOLD 100  // 静音阈值

// WiFi配置
#define WIFI_SSID "YOUR_WIFI_SSID"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#define WIFI_TIMEOUT 30000 // 30秒连接超时

// AI API配置
#define AI_API_URL "https://api.openai.com/v1/chat/completions"
#define AI_API_KEY "YOUR_API_KEY"
#define AI_MODEL "gpt-3.5-turbo"
#define AI_MAX_TOKENS 150
#define AI_TEMPERATURE 0.7

// 语音合成配置
#define TTS_API_URL "https://api.speech.microsoft.com/cognitiveservices/v1"
#define TTS_API_KEY "YOUR_TTS_KEY"
#define TTS_VOICE "zh-CN-XiaoxiaoNeural"
#define TTS_RATE "medium"

// 缓存配置
#define CACHE_SIZE 10
#define MAX_QUESTION_LENGTH 256
#define MAX_ANSWER_LENGTH 512

// 口语练习配置
#define PRACTICE_WORDS_COUNT 100
#define PRONUNCIATION_THRESHOLD 0.8
#define PRACTICE_TIMEOUT 30000

// 系统状态
typedef enum
{
    STATE_IDLE,
    STATE_LISTENING,
    STATE_PROCESSING,
    STATE_SPEAKING,
    STATE_PRACTICE,
    STATE_ERROR
} system_state_t;

// 语音识别结果
typedef enum
{
    VOICE_NONE,
    VOICE_WAKE_WORD,
    VOICE_QUESTION,
    VOICE_PRACTICE,
    VOICE_COMMAND
} voice_result_t;

// 错误代码
typedef enum
{
    ERROR_NONE,
    ERROR_WIFI_FAILED,
    ERROR_API_FAILED,
    ERROR_AUDIO_FAILED,
    ERROR_MEMORY_FULL,
    ERROR_TIMEOUT
} error_code_t;

// 调试配置
#define DEBUG_ENABLED 1
#define DEBUG_LEVEL 2 // 0:错误, 1:警告, 2:信息, 3:调试

#if DEBUG_ENABLED
#define DEBUG_PRINT(level, format, ...)                           \
    do                                                            \
    {                                                             \
        if (level <= DEBUG_LEVEL)                                 \
        {                                                         \
            printf("[%s] " format "\n",                           \
                   (level == 0) ? "ERROR" : (level == 1) ? "WARN" \
                                        : (level == 2)   ? "INFO" \
                                                         : "DEBUG", \
                   ##__VA_ARGS__);                                \
        }                                                         \
    } while (0)
#else
#define DEBUG_PRINT(level, format, ...)
#endif

// 内存配置
#define HEAP_SIZE 8192
#define STACK_SIZE 2048

// 定时器配置
#define TIMER_INTERVAL 100      // 100ms
#define HEARTBEAT_INTERVAL 1000 // 1秒心跳

// LED状态配置
#define LED_OFF 0
#define LED_ON 1
#define LED_BLINK_FAST 2
#define LED_BLINK_SLOW 3

// 按键配置
#define BUTTON_DEBOUNCE_TIME 50     // 50ms防抖
#define BUTTON_LONG_PRESS_TIME 2000 // 2秒长按

#endif // CONFIG_H